using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The MaritalStatusCodeTableManager class is responsible for managing BO.MaritalStatusCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class MaritalStatusCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all MaritalStatusCodeTable objects in the database.
/// </summary>
/// <returns>A list with all MaritalStatusCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static MaritalStatusCodeTableList GetList(){
return MaritalStatusCodeTableDB.GetList();
}

/// <summary>
/// Gets a single MaritalStatusCodeTable from the database without its data.
/// </summary>
/// <param name="maritalStatusCode">The MaritalStatusCode of the MaritalStatusCodeTable in the database.</param>
/// <returns>A MaritalStatusCodeTable object when the MaritalStatusCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static MaritalStatusCodeTable GetItem(short maritalStatusCode){
return GetItem(maritalStatusCode, false);
}

/// <summary>
/// Gets a single MaritalStatusCodeTable from the database.
/// </summary>
/// <param name="maritalStatusCode">The MaritalStatusCode of the MaritalStatusCodeTable in the database.</param>
/// <param name="getMaritalStatusCodeTableRecords">Determines whether to load all associated MaritalStatusCodeTable records as well.</param>
/// <returns>
/// A MaritalStatusCodeTable object when the MaritalStatusCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static MaritalStatusCodeTable GetItem(short maritalStatusCode, bool getMaritalStatusCodeTableRecords){
MaritalStatusCodeTable myMaritalStatusCodeTable = MaritalStatusCodeTableDB.GetItem(maritalStatusCode);
if (myMaritalStatusCodeTable != null && getMaritalStatusCodeTableRecords){
myMaritalStatusCodeTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByMartialStatusCode(maritalStatusCode);
}

//if (myMaritalStatusCodeTable != null && getMaritalStatusCodeTableRecords){
//myMaritalStatusCodeTable.guardianProfileTables = GuardianProfileTableDB.GetListByMartialStatusCode(maritalStatusCode);
//}
//if (myMaritalStatusCodeTable != null && getMaritalStatusCodeTableRecords){
//myMaritalStatusCodeTable.studentProfileTables = StudentProfileTableDB.GetListByMartialStatusCode(maritalStatusCode);
//}
//if (myMaritalStatusCodeTable != null && getMaritalStatusCodeTableRecords){
//myMaritalStatusCodeTable.teacherProfileTables = TeacherProfileTableDB.GetListByMartialStatusCode(maritalStatusCode);
//}
//if (myMaritalStatusCodeTable != null && getMaritalStatusCodeTableRecords){
//myMaritalStatusCodeTable.userProfileTables = UserProfileTableDB.GetListByMaritalStatusCode(maritalStatusCode);
//}
return myMaritalStatusCodeTable;
}

/// <summary>
/// Saves a MaritalStatusCodeTable in the database.
/// </summary>
/// <param name="myMaritalStatusCodeTable">The MaritalStatusCodeTable instance to save.</param>
/// <returns>The new MaritalStatusCode if the MaritalStatusCodeTable is new in the database or the existing MaritalStatusCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(MaritalStatusCodeTable myMaritalStatusCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short maritalStatusCodeTableMaritalStatusCode = MaritalStatusCodeTableDB.Save(myMaritalStatusCodeTable);

//foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myMaritalStatusCodeTable.familyMemberProfileTables){
//myFamilyMemberProfileTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;
//FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
//}
//foreach (GuardianProfileTable myGuardianProfileTable in myMaritalStatusCodeTable.guardianProfileTables){
//myGuardianProfileTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;
//GuardianProfileTableDB.Save(myGuardianProfileTable);
//}
//foreach (StudentProfileTable myStudentProfileTable in myMaritalStatusCodeTable.studentProfileTables){
//myStudentProfileTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;
//StudentProfileTableDB.Save(myStudentProfileTable);
//}
//foreach (TeacherProfileTable myTeacherProfileTable in myMaritalStatusCodeTable.teacherProfileTables){
//myTeacherProfileTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;
//TeacherProfileTableDB.Save(myTeacherProfileTable);
//}
//foreach (UserProfileTable myUserProfileTable in myMaritalStatusCodeTable.userProfileTables){
//myUserProfileTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;
//UserProfileTableDB.Save(myUserProfileTable);
//}

//  Assign the MaritalStatusCodeTable its new (or existing MaritalStatusCode).
myMaritalStatusCodeTable.MaritalStatusCode = maritalStatusCodeTableMaritalStatusCode;

myTransactionScope.Complete();

return maritalStatusCodeTableMaritalStatusCode;
}
}

/// <summary>
/// Deletes a MaritalStatusCodeTable from the database.
/// </summary>
/// <param name="myMaritalStatusCodeTable">The MaritalStatusCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(MaritalStatusCodeTable myMaritalStatusCodeTable){
return MaritalStatusCodeTableDB.Delete(myMaritalStatusCodeTable.MaritalStatusCode);
}

#endregion

}

}
